package com.hyperion.blog.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyperion.blog.admin.mapper.AdminMapper;
import com.hyperion.blog.admin.mapper.PermissionMapper;
import com.hyperion.blog.admin.pojo.Admin;
import com.hyperion.blog.admin.pojo.Permission;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Hyperion
 * @date 2021/10/24
 */
@Service
public class AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Resource
    private PermissionMapper permissionMapper;

    public Admin findAdminByUserName(String username) {
        LambdaQueryWrapper<Admin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Admin::getUsername, username);
        queryWrapper.last("limit 1");
        return adminMapper.selectOne(queryWrapper);
    }

    public List<Permission> getPermissionByAdminId(Long adminId) {
        return permissionMapper.findPermissionsByAdminId(adminId);
    }
}
